/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package ExamplePackage;

import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 *
 * @author tomato
 */
public class RegisterServlet extends HttpServlet {
   
   
 public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, java.io.IOException {

	try
	{

	UserBean user = new UserBean();					// Create an instant of the bean 'UserBean'

	user.setUserName(request.getParameter("un"));	// Get the username and password entered by the user in LoginPage.JSP
	user.setPassword(request.getParameter("pw"));	// in the fields named "un" and "pw", And save them to the bean
	user.setEmail(request.getParameter("email"));

	UserDAO.register(user);						// Call the DAO to ask the DB about the validity of this user
													// And send to it the user bean instance
    												// (which currently contains the username and password values only)


	HttpSession session = request.getSession(true);	 // Create a new session instance that will be with us
														 // throughout all the jsp pages
        													 // "currentSessionUser", so that userLogged.jsp can use it
														 // later to display the user's first and last names
        response.sendRedirect("Registered.jsp"); 		 

	}


	catch (Throwable theException)

	{
		System.out.println(theException);
	}

	}
}
